<template>
	<div class="app-container">
		<div class="no-print" style="height: 42px;"></div>
		<div style="width: 90%; margin: 0 auto">
			<div class="no-print" style="width: 10%;">.</div>
			<div class="width-100-percent print-content">
				<div style="font-size: 22px;text-align: center">过磅单</div>
				<div style="font-size: 18px; padding: 10px 0 10px 0">打印日期：{{ belongDate || '' }}</div>
				<div>
					<div style="display: flex; width: 100%; padding: 10px 0 10px 0">
						<span style="width: 50%">日期： {{ tableData.belongDate }}</span>
						<span style="width: 50%">运输单位： {{ tableData.transportName }}</span>
					</div>
					<div style="display: flex; width: 100%; padding: 10px 0 10px 0">
						<span style="width: 50%">车号： {{ tableData.carCode }}</span>
						<span style="width: 50%">计量单位： {{ tableData.unitName }}</span>
					</div>
				</div>
				<jk-table
					v-show="type !== 1"
					:header-cell-style="cellStyle"
					:cell-style="cellStyle"
					:row-style="cellStyle"
					:span-method="mergeColMethod"
					class="margin-bottom-10"
					border
					:data="tableData.itemList"
				>
					<vxe-column title="存货编码" align="left" field="productCode" width="70"></vxe-column>
					<vxe-column title="品种" align="left" field="productName" width="60"></vxe-column>
					<vxe-column title="到货单日期" align="left" field="belongDate" width="55"></vxe-column>
					<vxe-column title="供货单位" align="left" field="supplyName" width="75"></vxe-column>
					<vxe-column title="备注" align="left" field="paymentName" width="60"></vxe-column>
					<vxe-column title="到货日期" align="left" field="arrivalDate" width="55"></vxe-column>
					<vxe-column title="原批" align="left" field="primaryBatchCode" width="60"></vxe-column>
					<vxe-column title="厂批" align="left" field="workshopBatchCode" width="60"></vxe-column>
					<vxe-column title="毛重" align="left" field="grossWeight" width="45"></vxe-column>
					<vxe-column title="件数" align="left" field="count" width="45"></vxe-column>
					<vxe-column title="皮重(kg)" align="left" field="tare" width="45"></vxe-column>
					<vxe-column title="净重" align="left" field="netWeight" width="45"></vxe-column>
				</jk-table>
			</div>
			<div>
				<div style="display: flex; width: 100%; padding: 10px 0 10px 0">
					<span style="width: 33.33%">记录人： {{ tableData.recordName }}</span>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
    import XEUtils from 'xe-utils';
    import {
        productionTechnologySettingsPage
    } from '../../../../api/technology/technologySet';
    import { formatDate } from '../../../../utils/jk/jk-tool';

    export default {
        mixins: [],
        components: {
        },
        data() {
            return {
                searchParams: {},
                tableHeader: [],
                tableData: [],
                dataId: null,
                reportData: [],
                type: null,
                belongDate: ''
            };
        },
        methods: {
            cellStyle() {
                return {
                    border: 'solid 1px black'
                };
            },
            mergeColMethod({ row, _rowIndex, column, visibleData }) {
                if (row.processName && column.property === 'processName') {
                    const prevRow = visibleData[_rowIndex - 1];
                    let nextRow = visibleData[_rowIndex + 1];
                    if (prevRow && prevRow.processName === row.processName) {
                        return { rowspan: 0, colspan: 0 };
                    } else {
                        let countRowspan = 1;
                        while (nextRow && nextRow.processName === row.processName) {
                            nextRow = visibleData[++countRowspan + _rowIndex];
                        }
                        if (countRowspan > 1) {
                            return { rowspan: countRowspan, colspan: 1 };
                        }
                    }
                } else if (row.empString && column.property === 'empString') {
                    const prevRow = visibleData[_rowIndex - 1];
                    let nextRow = visibleData[_rowIndex + 1];
                    if (prevRow && prevRow.empString === row.empString) {
                        return { rowspan: 0, colspan: 0 };
                    } else {
                        let countRowspan = 1;
                        while (nextRow && nextRow.empString === row.empString) {
                            nextRow = visibleData[++countRowspan + _rowIndex];
                        }
                        if (countRowspan > 1) {
                            return { rowspan: countRowspan, colspan: 1 };
                        }
                    }
                }
            },
            footerMethod({ columns, data }) {
                return [
                    columns.map((column, columnIndex) => {
                        if (columnIndex === 0) {
                            return '合计:';
                        }
                        if (['totalSalary'].includes(column.property)) {
                            if (column.property === 'totalSalary') {
                                return XEUtils.sum(data, column.property);
                            }
                            return XEUtils.sum(data, column.property);
                        }
                        return null;
                    })
                ];
            },
            onPrintBtn() {
                window.print();
            },
            getMachineListRequest() {
                this.tableLoading = true;
                return productionTechnologySettingsPage(this.searchParams).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.reportData = res.data.res || {};
                    }
                });
            }
        },
        mounted() {
            this.type = this.$route.query.ids ? Number(this.$route.query.ids) : null;
            this.searchParams = this.$route.query;
            // this.getMachineListRequest();
            this.belongDate = formatDate(Date.now());
        }
    };
</script>

<style scoped lang="scss">

.print-content {
  ::v-deep .vxe-table--render-default {
    position: relative;
    border: solid 2px black!important;
    font-size: 12px;
    color: #606266;
    font-family: -apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
    direction: ltr;
  }
}
.table {
  width: 100%;
  padding: 0;
  margin: 0;
  border-collapse: collapse;
  box-sizing: border-box;
  font-weight: 500;
  tr {
    //height: 139px;
    border: solid 2px #17233d;
  }
  td {
    min-width: 100px;
    box-sizing: border-box;
    padding: 10px;
    border: solid 2px #17233d;
    text-align: center;
  }
  .form-title {
    font-weight: 500;
    font-size: 36px;
  }
  .label-name {
    font-weight: 500;
    font-size: 28px;
  }
}
@media print {
  .no-print{
    display: none;
  }
}
@page {
  /*横向打印landscape,纵向打印portrait*/
  size: portrait;
  /*去除页眉页脚-size和margin同时使用*/
  margin: 2mm; /* this affects the margin in the printer settings */
}
</style>
